package com.txts.data.common;


import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

/**
 * 请求返回对象
 *
 * @Author 卓大
 * @Date 2021-10-31 21:06:11
 * @Wechat zhuoda1024

 * 
 */
@Data
@Schema
public class ResponseDTO<T> {

    public static final int OK_CODE = 0;

    public static final int ERROR_CODE = 500;

    public static final String OK_MSG = "操作成功";

    public static final String ERROR_MSG = "操作失败";

    @Schema(description = "返回码")
    private Integer code;

    private String msg;

    private Boolean ok;

    @Schema(description = "返回数据")
    private T data;


    public ResponseDTO(Integer code, boolean ok, String msg, T data) {
        this.code = code;
        this.ok = ok;
        this.msg = msg;
        this.data = data;
    }

    public ResponseDTO(Integer code, boolean ok, String msg) {
        this.code = code;
        this.ok = ok;
        this.msg = msg;
    }


    public static <T> ResponseDTO<T> ok() {
        return new ResponseDTO<>(OK_CODE, Boolean.TRUE, OK_MSG, null);
    }

    public static <T> ResponseDTO<T> ok(T data) {
        return new ResponseDTO<>(OK_CODE, Boolean.TRUE, OK_MSG, data);
    }

    public static <T> ResponseDTO<T> ok(T data, String msg) {
        return new ResponseDTO<>(OK_CODE, Boolean.TRUE, msg, data);
    }

    public static <T> ResponseDTO<T> ok(String msg) {
        return new ResponseDTO<>(OK_CODE, Boolean.TRUE, msg, null);
    }

    public static <T> ResponseDTO<T> error() {
        return new ResponseDTO<>(ERROR_CODE, Boolean.FALSE, ERROR_MSG, null);
    }

    public static <T> ResponseDTO<T> error(String msg) {
        return new ResponseDTO<>(ERROR_CODE, Boolean.FALSE, msg, null);
    }


}
